package hadoop.topN.question3;

import hadoop.topN.question2.StuBean;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class StuReducer3 extends Reducer<Text, StuBean, StuBean, NullWritable> {



    @Override
    protected void reduce(Text key, Iterable<StuBean> values, Context context) throws IOException, InterruptedException {
        StuBean sb = new StuBean();

        for (StuBean value : values) {
            if (value.getSelfAvg() > sb.getSelfAvg()) {
                sb.setStuName(value.getStuName());
                sb.setSelfAvg(value.getSelfAvg());
                sb.setCourseName(value.getCourseName());
            }
        }

        context.write(sb, NullWritable.get());

    }
}
